package com.intramirror.product.service.impl;

import com.intramirror.product.entity.FeaturedBrand;
import com.intramirror.product.mapper.FeaturedBrandMapper;
import com.intramirror.product.service.IFeaturedBrandService;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created on 2018/7/3.
 * @author 123
 */
@Service
public class FeaturedBrandServiceImpl implements IFeaturedBrandService {
    private static final Logger LOGGER = LoggerFactory.getLogger(FeaturedBrandServiceImpl.class);

    @Autowired
    FeaturedBrandMapper featuredBrandMapper;

    @Override
    public List<FeaturedBrand> getFeaturedBrandList() {
        return featuredBrandMapper.getFeaturedBrandList();
    }

    @Override
    public void updateFeaturedBrand(FeaturedBrand featuredBrand) {
        featuredBrandMapper.updateFeaturedBrand(featuredBrand);
    }

    @Transactional
    @Override
    public void addFeatureBrandList(List<FeaturedBrand> featuredBrandList) {
        // 1. delete all feature brand list

        Long t1 = System.currentTimeMillis();
        LOGGER.info("Start to remove all featured brand for updated.");
        featuredBrandMapper.removeAllFeaturedBrand();

        Long t2 = System.currentTimeMillis();
        featuredBrandMapper.addFeaturedBrands(featuredBrandList);

        Long t3 = System.currentTimeMillis();

        LOGGER.info("Add  featured brand success, remove takes {}ms, add takes {}ms, total {}ms.", t2 - t1, t3 - t2, t3 - t1);

        // 2. insert into
        //        for (FeaturedBrand featuredBrand : featuredBrandList) {
        //            featuredBrandMapper.addFeaturedBrand(featuredBrand);
        //        }
    }
}
